package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yupi.springbootinit.utils.RabbitMqUtils;

import java.nio.charset.StandardCharsets;

/**
 * 用于创建测试程序用到的交换机和队列（只用在程序启动前执行一次）
 */
public class BiInitMain {

    public static void main(String[] args) {
        try (Channel channel = RabbitMqUtils.getChannel()) {

            // 声明死信交换机
            channel.exchangeDeclare(BiMqConstant.DEAD_EXCHANGE_NAME, "direct");
            // 创建死信队列
            channel.queueDeclare(BiMqConstant.DEAD_QUEUE_NAME, true, false, false, null);
            channel.queueBind(BiMqConstant.DEAD_QUEUE_NAME, BiMqConstant.DEAD_EXCHANGE_NAME, BiMqConstant.DEAD_ROUTING_KEY);

            //工作交换机
            String EXCHANGE_NAME = BiMqConstant.BI_EXCHANGE_NAME;
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");

            // 创建工作队列
            String queueName = BiMqConstant.BI_QUEUE_NAME;
            channel.queueDeclare(queueName, true, false, false, null);
            channel.queueBind(queueName, EXCHANGE_NAME, BiMqConstant.BI_ROUTING_KEY);
        } catch (Exception ignored) {
        }

    }
}
